<script type="text/javascript" src="paging.js"></script>

<?php
	include_once "../classes/hoadon_bs.php";
	
	$Courses = trim($_GET['cou']);
	$Keyword = trim($_GET['key']);
	$Page    = trim($_GET['pag']);
	$MaNguoiDung = trim($_GET['mnd']);
	$HoaDon = new hoadon_bs();
	
	$Limit = 20;
	if($MaNguoiDung != '')
		$HoaDon->SetMaNguoiDung($MaNguoiDung);
	if($Courses == "" || $Courses == "0")
	{
		$DHoaDon = $HoaDon->LayDanhSach();
		$SoTrang = ceil(count($DHoaDon) / $Limit);
		$DHoaDon = $HoaDon->LayDanhSachPaging(($Page - 1) * $Limit, $Limit);
	}
	else
	{
		$DHoaDon = $HoaDon->LayDanhSachTheoKhoa($Courses);
		$SoTrang = ceil(count($DHoaDon) / $Limit);
		$DHoaDon = $HoaDon->LayDanhSachTheoKhoaPaging($Courses ,($Page - 1) * $Limit, $Limit);
	}
	
	
?>
<div class="Paging">
	<?php
		if($DHoaDon != null)
		{
			if($Page > 1)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLHoaDon(\"$MaNguoiDung\",\"$Courses\",\"$Keyword\",1);'>Đầu</a>";	
			for($i = 1; $i <= $SoTrang; $i++)
			{
				if($Page - 5 <= $i && $i <= $Page + 5)
				{
					if($i == $Page)
						echo "<a class='AjaxPageCur' href='#' onclick='javascript:loadXMLHoaDon(\"$MaNguoiDung\",\"$Courses\",\"$Keyword\",$i);'>$i</a>";
					else
						echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLHoaDon(\"$MaNguoiDung\",\"$Courses\",\"$Keyword\",$i);'>$i</a>";
				}
				elseif($i == $Page + 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLHoaDon(\"$MaNguoiDung\",\"$Courses\",\"$Keyword\",$i);'>...</a>";
				elseif($i == $Page - 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLHoaDon(\"$MaNguoiDung\",\"$Courses\",\"$Keyword\",$i);'>...</a>";
			}
			if($Page < $SoTrang)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLHoaDon(\"$MaNguoiDung\",\"$Courses\",\"$Keyword\",$SoTrang);'>Cuối</a>";	
			
			echo "<span style='float:right; background-color:#4ABDF4; color: #FFF; padding:0px 3px'>Trang $Page/$SoTrang</span>";
		}
	?>
</div>
<div id="KetQuaTimKiem">
	<table id="DataReport">
		<tr>
			<th rowspan="2" class="first">STT</th>
			<th rowspan="2">Mã học viên</th>
			<th rowspan="2" colspan="2">Họ tên</th>
			<th rowspan="2">Điện thoại</th>
			<th rowspan="2">Nội dung nộp</th>
			<th rowspan="2">Ngày lập</th>
			<th rowspan="2">Người lập</th>
			<th rowspan="2">Thành tiền</th>
			<th colspan="3">Tùy chọn</th>
		</tr>
		<tr>
			<th>Chi tiết</th>
			<th>Cập nhật</th>
			<th>Xóa</th>
		</tr>
		<!-- Lấy danh sách học viên từ cơ sở dữ liệu -->
		<?php
			if($DHoaDon == null)
			{
				echo '<tr><td colspan="12" align="center"> Nội dung rỗng</td></tr>';
			}
			else
			{
				for($i = 0; $i < count($DHoaDon); $i++)
				{
					include_once "../classes/hocvien_bs.php";
					$HocVien = new hocvien_bs();
					$HocVien->SetMaHocVien($DHoaDon[$i]['MaHocVien']);
					$DHocVien = $HocVien->LayDanhSach();
					
					include_once "../classes/chuongtrinhhoc_bs.php";
					$ChuongTrinhHoc = new chuongtrinhhoc_bs();
					$ChuongTrinhHoc->SetMaChuongTrinh($DHoaDon[$i]['MaChuongTrinh']);
					$DChuongTrinhHoc = $ChuongTrinhHoc->LayDanhSach();
					
					include_once "../classes/nguoidung_bs.php";
					$NguoiDung = new nguoidung_bs();
					$NguoiDung->SetMaNguoiDung($DHoaDon[$i]['MaNguoiDung']);
					$DNguoiDung = $NguoiDung->LayDanhSach();
					
					$Id = $DHoaDon[$i]['MaHoaDon'];
					$PIN = $DHoaDon[$i]['PIN'];
					$LinkDetails = "index.php?act=hoadon_chitiet&id=" . $Id . "&pin=" . $PIN;
					$LinkUpdate = "index.php?act=hoadon_capnhat&id=$Id&pin=$PIN";
					$LinkDelete = "index.php?act=hoadon_xoa&id=$Id&pin=$PIN";
					
					$HT = TachHoTen($DHocVien[0]['HoTen']);
					echo '<tr class="ButtonDetails">';
						echo '<td align="center"><b>' . (($Page - 1) * $Limit + ($i + 1)) . '</b></td>';
						echo '<td>' . $DHocVien[0]['MaHocVien'] . '</td>';
						echo '<td>' . $HT[0] . '</td>';
						echo '<td>' . $HT[1] . '</td>';
						echo '<td>' . $DHocVien[0]['DienThoai'] . '</td>';
						echo '<td> HP.' . $DChuongTrinhHoc[0]['TenChuongTrinh'] . '</td>';
						echo '<td>' . ConvertDate($DHoaDon[$i]['NgayLap']) . '</td>';
						echo '<td>' . $DNguoiDung[0]['HoTen'] . '</td>';
						echo '<td align="center">' . number_format($DHoaDon[$i]['ThanhTien'], 0, '.', ',') . '</td>';
						
						echo '<td align="center"><a href="' . $LinkDetails . '"><img src="../data/details.png" alt="" /></a></td>';
						echo '<td align="center"><a href="' . $LinkUpdate . '"><img src="../data/edit.png" alt="" /></a></td>';
						echo '<td align="center"><a onclick="return confirm(\'Bạn muốn xóa hóa đơn?\')" href="' . $LinkDelete . '"><img src="../data/shiftdetete.png" alt="" /></a></td>';
					echo '</tr>';
				}
			}
		?>
	</table>
</div>


